/// <reference path="references.scss" />

// Functions
// ===============================================

$scrim-gradient-coords: (
    0: 1,
    19: 0.738,
    34: 0.541,
    47: 0.382,
    56.5: 0.278,
    65: 0.194,
    73: 0.126,
    80.2: 0.075,
    86.1: 0.042,
    91: 0.021,
    95.2: 0.008,
    98.2: 0.002,
    100: 0
);

@function scrim-gradient($start-color: #000, $direction: 'to bottom', $radial: false) {
    $hue: hue($start-color);
    $saturation: saturation($start-color);
    $lightness: lightness($start-color);
    $stops: ();

    @each $colorstop, $alpha in $scrim-gradient-coords {
        $stop: hsla(
                $hue, 
                $saturation, 
                $lightness, 
                $alpha
            ) 
            calc(var(--cstartpos, 0%) + (#{$colorstop / 100} * (var(--cendpos, 100%) - var(--cstartpos, 0%))));
        $stops: append($stops, $stop, comma);
    }

    @return if(
        $radial,
        radial-gradient(unquote(#{$direction}), #{$stops}),
        linear-gradient(unquote(#{$direction}), #{$stops})
    );
}

@function scrim-gradient-generic($direction: 'to bottom', $radial: false) {
    $stops: ();

    @each $colorstop, $alpha in $scrim-gradient-coords {
        $stop: rgba(var(--cstart-rgb), $alpha) 
            calc(var(--cstartpos, 0%) + (#{$colorstop / 100} * (var(--cendpos, 100%) - var(--cstartpos, 0%))));
        $stops: append($stops, $stop, comma);
    }

    @return if(
        $radial,
        radial-gradient(unquote(#{$direction}), #{$stops}),
        linear-gradient(unquote(#{$direction}), #{$stops})
    );
}

@function color-yiq-ex($color, $text-dark: $yiq-text-dark, $text-light: $yiq-text-light) {
	$r: red($color);
	$g: green($color);
	$b: blue($color);

	$yiq: (($r * 299) + ($g * 587) + ($b * 114)) / 1000;

	@if ($yiq >= $yiq-contrasted-threshold) {
		@return $text-dark;
	}
	@else {
		@return $text-light;
	}
}